package com.shangxia.monomer.common.util.file;

import java.io.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author zhouya38158
 * @Package com.shangxia.monomer.common.util.file
 * @date 2021/7/26 9:44
 */
public class IOUtil {

    public static void main(String[] args) {

    }

    public static List<String> readFile(String fileName) throws FileNotFoundException {
        try (Stream<String> stream = new BufferedReader(new FileReader(fileName)).lines()) {
            return stream.collect(Collectors.toList());
        }
    }

    public static String inputStreamToString(InputStream inputStream) throws IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            StringBuilder stringBuilder = new StringBuilder();
            int data = reader.read();

            while (data != -1) {
                stringBuilder.append((char) data);
                data = reader.read();
            }
            return stringBuilder.toString();
        }
    }
}